class Solution
{
public:
    int earliestFullBloom(vector<int> &plantTime, vector<int> &growTime)
    {
        int n = plantTime.size();
        vector<int> id(n);
        iota(id.begin(), id.end(), 0);
        sort(id.begin(), id.end(), [&](int i, int j)
             { return growTime[i] > growTime[j]; });

        int curTime = 0;
        int result = 0;
        for (int i : id)
        {
            curTime += plantTime[i];
            result = max(curTime + growTime[i], result);
        }
        return result;
    }
};